<template>
	<div id="tenant_apply">
		<el-form :inline="true" size="medium">
			<el-form-item>
				<el-date-picker v-model="selectData" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" clearable @change="search">
				</el-date-picker>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="search">搜索</el-button>
			</el-form-item>
		</el-form>

		<el-table :data="list" v-loading="loading" stripe>
			<el-table-column label="id" prop="id" align="center"></el-table-column>
			<el-table-column label="操作" align="center">
				<template slot-scope="scope">
				</template>
			</el-table-column>
		</el-table>

		<el-pagination 
			class="page"
			background
			@size-change="handleSizeChange" 
			@current-change="getList" 
			:current-page.sync="params.pageNo" 
			:page-sizes="[10, 20, 50, 100]" 
			:page-size="params.pageSize" 
			layout="total, sizes, prev, pager, next, jumper" 
			:total="total">
		</el-pagination>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				params: {
					pageNo: 1,
					pageSize: 10,
					isCount: true,
				},
				list: [],
				total: 0,
				loading: false,
				selectData: []
			};
		},

		watch: {},

		create() {},

		mounted() {
			// this.getList();
		},

		methods: {
			handleSizeChange(value) {
				this.params.pageSize = value 
				this.search()
			},
			
			search(){
				this.params.pageNo = 1
				this.params.isCount = true 
				if(this.selectData){
					this.params.startTime = this.$moment(this.selectData).format('Y-MM-DD HH:mm:ss')
					this.params.endTime = this.$moment(this.selectData).add(1, 'days').format('Y-MM-DD HH:mm:ss') 
				}else{
					this.selectData = []
				}
				this.getList();
			},
			
			getList() {
				this.loading = true
				this.$request.post({
					url: 'list',
					params: this.params,
					success: result =>{
						this.list = result.list 
						if(this.params.isCount){
							this.params.isCount = false 
							this.total = result.total
						}
					},
					finally: ()=>{
						this.loading = false 
					}
				})
			}
		},

		beforeDestroy() {}
	}
</script>

<style>

</style>

<style lang="scss" scoped>
	.page{
		text-align: right;
		margin-top: 20px;
	}
</style>
